home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-02 | 2.8 KB | 107 lines | [TEXT/????] |
- NB. conversion utilities
- NB.
- NB. av convert between characters and indices
- NB. chop chop array into boxed list
- NB. detab remove tab stops
- NB. dfh decimal from hex
- NB. exportfmt export format numeric data
- NB. hfd hex from decimal
- NB. vfm vector from matrix
- NB. mfv matrix from vector
- NB. quote quote text
- NB. tolower to lower case
- NB. toupper to upper case
- NB. toCR convert to CR separator
- NB. toLF convert to LF separator
- NB. toCRLF convert to CRLF separator
- NB. toSUB convert to 1{a. separator
- NB. toLFTAB convert TAB to LF
-
- t=. 'av chop detab dfh exportfmt hfd vfm mfv quote'
- t=. t,' subs tolower toupper toCR toLF toCRLF toSUB toLFTAB'
- SCRIPTNAMES=: t
-
- hex=. '0123456789ABCDEF'
- dfh=: 16. @ (hex&i.) f.
- hfd=: hex&({~) @ (16 16:) f.
-
- NB. av
- NB. e.g av 'abcde'
- av=: '({&a.)`(a.&i.) @. (2&=@(3!:0)) y.' :0
-
- TAB =. 9{a.
- LF =. 10{a.
- CR =. 13{a.
- CRLF =. 13 10{a.
- EAV =. 255{a.
-
- subs=. [. & ((((e.&) (# i.@#@)) (@])) })
- crlf=. #~ -.@(CRLF&E.)
-
- toLF=: LF subs CR @ crlf f.
- toCR=: CR subs LF @ crlf f.
- toSUB=: (1{a.) subs (CR,LF) @ crlf f.
- toCRLF=: 2&}.@;@(((CR&,)&.>)@<;.1@(LF&,)@toLF)
- toLFTAB=: LF subs TAB f.
-
- NB. quote
- NB. quote 'Pete''s Place'
- a=. ''''
- quote=: (a&,@(,&a))@ (#~ >:@(=&a))
-
- NB. chop
- NB. chop character vector or matrix into boxed list
- NB. x. is optional delimiter, default blank
- NB. e.g. chop ": 10 20 30
- NB. chop ": i. 5 4
- chop=: 0 : 0
- ' ' chop y.
- :
- $.=. >(2=#$y.){ ({.;}.)$.
- (<'') -.~ (y e.x.) <;._2 y=. y.,{.x.
- |: &.> y -. {: y=. (*./y e.x.) <;._2 |: y=. y.,"1 [ 2${.x.
- )
-
- NB. detab
- NB. remove tabs from character string
- NB. left argument is tab width, default 4
- a=. 0 : 0
- 4 detab y.
- :
- NB. replace tabs in text
- tab=. 9{a.
- r=. y.
- L0) i=. >: r i. tab
- r [ $.=. $.#~ i<:#r
- r=. ((x. * >. i % x.){.!.' ' }:i{.r) , i}.r
- $.=. L0
- )
- detab=: a"1 f.
-
- NB. exportfmt
- NB. format numeric array of rank 0 1 or 2 as required
- NB. by other software, e.g. Excel
- NB. numbers are separated by TAB, rows by CR
- exportfmt=: 0 : 0
- 'rc'=. $ ,.y.
- dat=. ,y.
- dat=. ":&.>dat
- sep=. 1|.((#dat)$c{.1) { 9 10{a.
- dat=. ;dat,&.>sep
- '-' subs '_' dat
- )
-
- NB. vector <> matrix, lines separated by LF
- mfv=: '];._2 y,LF #~ LF ~: {:y=. toLF y.' :0
- vfm=: '}:(,|."1 [ 1,.-. *./\"1 |."1 y.='' '')#,y.,.LF' :0
-
- NB. tolower
- j=. '(y.i.~''ABCDEFGHIJKLMNOPQRSTUVWXYZ'',a.)'
- j=. j,'{''abcdefghijklmnopqrstuvwxyz'',a.'
- tolower=: j : ''
-
- NB. toupper
- j=. '(y.i.~''abcdefghijklmnopqrstuvwxyz'',a.)'
- j=. j,'{''ABCDEFGHIJKLMNOPQRSTUVWXYZ'',a.'
- toupper=: j : ''
-